$(function () {
    //回到顶部
    $(".xx_top ").click(function () {
        $("html,body").animate({
            scrollTop: 0
        }, 1000)
    })


    //显示隐藏菜单 nav-菜单
    $(".nav-down").hover(function () {
        $(this).children(".nav-down-menu").show()
    }, function () {
        $(this).children(".nav-down-menu").hide()
    })

    //轮播图
    function slide() {
        var slide_obj = [{ 'background': '162609', 'href': 'baidu.com' },
        { 'background': '162632', 'href': 'tudou.com' },
        { 'background': '162928', 'href': 'sina.com' },
        { 'background': '162930', 'href': '36kr.com' },
        { 'background': '162932', 'href': 'sogou.com' }]
        $.each(slide_obj, function (i, n) {
            //添加大slider
            var slider_item = `<li class="slider-item"><div class="bannersize" style="background:url(./img/` + n.background + `.png) no-repeat center top;"><a class="a-img-bg" href="http://www.` + n.href + `" target="_blank"></a></div></li>`
            $(".ck-slide-wrapper").append(slider_item);
            //添加小slider
            var dot_wrap = `<li class="small-ban-list"><a href="javascript:;" class="small-cover"></a><a href="javascript:;"><img src="./img/` + n.background + `_80_45.png" alt=""></a></li>`;
            $(".dot-wrap").append(dot_wrap);
        });
        $('.ck-slide').ckSlide({
            autoPlay: true,
            // dir: "x"
        });
    }
    slide();

    //关闭下载页面
    var navBgScroollFlag = false;
    $('.container').css({ height: '800px' });
    $('.container').stop().animate({ height: "161px" }, 1500, function () {
        //隐藏大的背景图-显示小的背景图-显示导航
        $(this).children('.big').stop().fadeOut(function () {
            $('.container .small').stop().show();
        });
        //绝对定位导航栏
        $('.nav-bg').css({ position: 'fixed', top: 84, zIndex: 11111 });
        $('.wraper-bg').css({ position: 'static' });
        //网上滚动32pxbug--去除多余32pxbug
        var scrollTop = $(window).scrollTop();//滚动上卷距离
        var navBgHight = $('.nav-head-bg').height();
        $(window).scrollTop(scrollTop - navBgHight);
        setTimeout(pc_close, 5000);//5s后关闭下载页面
    });
    $(".pc-close").on('click', pc_close);//绑定PC-close点击事件
    function pc_close() {
        //关闭pcdown
        $(".pcdown").stop().slideUp();
        navBgScroollFlag = true;
        navBgScrooll(); //根据scrollTop的距离修改nav
    }


    //nav --上卷距离 --- 滚动高度大于navBghight=32;固定wraper-bg导航栏-隐藏head-bg导航栏 否则静态化 
    function navBgScrooll() {
        if (!navBgScroollFlag) return false;  //如果下载页面未执行完毕，执行下载页面程序
        var navBgHight = $('.nav-head-bg').height();
        var scrollTop = $(window).scrollTop();//滚动上卷距离
        if (scrollTop > navBgHight) {
            $('.wraper-bg').css({ position: 'fixed', top: 0, zIndex: 1000 });
            $('.nav-head-bg').hide()
        } else {
            $('.nav-head-bg').show()
            $('.nav-bg,.wraper-bg,.nav-head-bg').css({ position: 'static' });
        }
    }

    //match-tab-栏目加载-页面加载---栏目切换
    $("#recent_list").append(all_page); //默认加载初始页
    $(".last-list a").click(function () {
        return $(this).hasClass("on") ? !true : ($(this).addClass("on").siblings().removeClass("on"),
            $("#recent_list").html(""), page_type = $(".last-list a.on").data("type"), getHotPage())
    })
    function getHotPage() {
        switch (page_type) {
            case 'all':
                $("#recent_list").append(all_page);
                break;
            case 'match':
                $("#recent_list").append(match_page);
                break;
            case 'event':
                $("#recent_list").append(event_page);
                break;
            case 'skill':
                $("#recent_list").append(skill_page);
                break;
            case 'people':
                $("#recent_list").append(people_page);
                break;
            default:
                $("#recent_list").append(all_page);
        }
    }
    //match-tab-more-更多页面加载
    $("#more").click(function () {
        page_type = $(".last-list a.on").data("type");
        switch (page_type) {
            case 'all':
                $("#recent_list").append(all_page_more);
                break;
            case 'match':
                $("#recent_list").append(match_page_more);
                break;
            case 'event':
                $("#recent_list").append(event_page_more);
                break;
            case 'skill':
                $("#recent_list").append(skill_page_more);
                break;
            case 'people':
                $("#recent_list").append(people_page_more);
                break;
            default:
                $("#recent_list").append(all_page_more);
        }
        return false; //阻止冒泡跳转等
    })

    //fixSideBar-滚动代码
    function fixSideBar() {
        var scrollTop = document.body.scrollTop || document.documentElement.scrollTop //滚动上卷距离
            , rightHeight = $(".right-fixed").height()
            , rightTop = $(".right-fixed").offset().top
            , leftHeight = $(".left").height()
            , leftTop = $(".left").offset().top
            , windowView = $(window).height()//window 可视宽度
            , k = windowView - rightHeight + 8//底部距离
        //左距离 scrollTop+windowView <leftTop + rightHeight --- 上滚距离+视口<右侧栏高度 静态
        if (scrollTop + windowView < leftTop + rightHeight) $(".right-fixed").css({ position: "static" });
        //左距离 scrollTop+windowView <leftTop + rightHeight --- 上滚距离+视口<右侧栏高度 静态
        if (leftTop + rightHeight < scrollTop + windowView && scrollTop + windowView < leftTop + leftHeight) {
            $(".right-fixed").css({
                position: "fixed",
                top: k
            })
        }
        //windowView - leftHeight-(scrollTop+wndowView -rightTop - rightHeight)
        if (scrollTop + windowView > leftTop + leftHeight) {
            $(".right-fixed").css({
                position: "fixed",
                top: k - (scrollTop + windowView - leftTop - leftHeight)
            })
        }
    }
    //滚动加载事件监听
    $(window).scroll(function () {
        fixSideBar();  //右侧栏固定
        //返回顶部图标-滚动距离超过--视口一屏高度显示--否则隐藏
        $(document).scrollTop() >= $(window).height() ? $(".xx_top").show() : $(".xx_top").hide()
        //头部nav 中 wraper-bg 固定与静态化
        navBgScrooll();
    });
})